<template>
  <erp-form-popover
    :title="title"
    :field="field"
    :value="value"
    :props="props"
    :extra="extra"
    :options="options"
    :form="form"
    @value-change="handleValueChange"
    @update-id-field="handleUpdateField"
  />
</template>

<script>
import ErpFormPopover from './ErpFormPopover';
/**
 * 供应商选择
 * @author maolin
 */
export default {
  name: "ErpFormNewSupplier",
  components: {
    ErpFormPopover
  },
  props: {
    /**
     * 标题
     * @public
     */
    title: {
      type: String,
      default: '',
    },
    /**
     * 字段
     * @public
     */
    field: {
      type: String,
      default: ''
    },
    /**
     * 值
     * @public
     */
    value: {
      default () {
        return '';
      }
    },
    /**
     * 属性
     * @public
     */
    props: {
      type: Object,
      default () {
        return {};
      }
    },
    /**
     * 额外配置
     * ```js
     * return {
          // 表单需要的id字段
          idField: '',
          inputPlaceholder: '',
          modalTitle: '',
          modalWidth: null,
          modalHeight: null,
          // 模态框表格中name对应的字段名
          modalNameField: null,
          // 模态框表格中id对应的字段名
          modalIdField: null,
          // 是否转换为字符串
          needToString: false,
          // 关联额外字段，除了id和name之外还需要关联字段时
          extraData: [
            // {
            //     // 外部id
            //     field: "userId",
            //     // 内部id
            //     relatedField: "id",
            // }
          ]
        }
     * ```
     * @public
     */
    extra: {
      type: Object,
      default () {
        return {
          // 表单需要的id字段
          idField: '',
          inputPlaceholder: '',
          modalTitle: '',
          modalWidth: null,
          modalHeight: null,
          // 模态框表格中name对应的字段名
          modalNameField: null,
          // 模态框表格中id对应的字段名
          modalIdField: null,
          // 是否转换为字符串
          needToString: false,
          // 关联额外字段，除了id和name之外还需要关联字段时
          extraData: [
            // {
            //     // 外部id
            //     field: "userId",
            //     // 内部id
            //     relatedField: "id",
            // }
          ]
        };
      }
    },
    /**
     * 表单对象
     * @public
     */
    form: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    const options = {
      "type": "singleSelect",
      "name": "basSupplierManager",
      "title": "供应商管理",
      "table": {
        "props": {
          "resizable": true
        },
        "permissions": ["basSupplier:basSupplierList"],
        "rowKey": "id",
        "list": [
        ],
        "fields": [
          {"label": "编号", "width": "100", "fixed": null, "prop": "code", "sortable": "custom"},
          {"label": "产品名称", "width": "120", "fixed": null, "prop": "name"},
          {"label": "型号规格", "width": "100", "fixed": null, "prop": "modelSpecs", "sortable": "custom"},
        ],
        "border": false,
        "showPagination": true,
        "showOrderNumber": true,
        "selectable": false,
        "defaultExpandAll": true,
        "showExport": false,
        "customColumn": false,
        "operationWidth": "100"
      },
      "search": {
        "form": {
          "pageOrderBy": null,
          "pageOrderDir": null,
          "pageIndex": 1,
          "pageSize": 30
        },
        "showKeywordQuery": true,
        "headSearchPlaceholder": "供应商名称",
        "showAdvancedQuery": false,
      },
      "apiList": {
        "list": "/invOrderInit/invOrderInitAddInitMaterial",
      },
      "components": {
      },
      "buttons": [
      ]
    };
    return {
      options: options
    };
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
  },
  methods: {
    /**
     * 监听表单其他值更新
     * @private
     * @param {object} obj 其他值对象{表单字段1：表单值1，表单字段2： 表单值2}
     */
    handleValueChange (value) {
      this.$emit('value-change', value);
    },
    /**
     * 监听表单其他值更新
     * @private
     * @param {object} obj 其他值对象{表单字段1：表单值1，表单字段2： 表单值2}
     */
    handleUpdateField (obj) {
      this.$emit('update-id-field', obj);
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
